package com.spring.boot.rabbit.components;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * 默认的消息确认回调函数
 *
 * @author 李坤
 * @date 2022/9/1 16:38
 */
@Component
public class DefaultConfirmCallback implements RabbitTemplate.ConfirmCallback {

    /**
     * 日志处理器
     */
    private final Logger logger = LoggerFactory.getLogger(DefaultConfirmCallback.class);

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        final String id = correlationData.getId();

        if (ack) {
            logger.info("生产者-消息投递确认-{{}}-发送结果: 成功", id);
        } else {
            logger.info("生产者-消息投递确认-{{}}-发送结果: 失败；原因-{}", id, cause);
        }
    }

}
